package com.wyd.rocketmq.test;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

//生产者，产生消息
public class Producer {
    public static void main(String[] args) throws Exception {
        //1 创建生产者对象,参数1：生产者组
        DefaultMQProducer producer=new DefaultMQProducer("group1");
        //2 指定nameserver地址，连接nameserver
        producer.setNamesrvAddr("120.24.68.195:9876");
        //3 启动生产者服务
        producer.start();
        //循环发送10条消息到
        for (int i = 1; i <= 10; i++) {
            //4 发送消息
            Message message=new Message("topic2",("hello rocketmq "+i).getBytes("utf-8"));
            SendResult result = producer.send(message);
            //5 打印结果信息
            System.out.println(result);
        }
        //5 断开连接，释放资源
        producer.shutdown();
    }
}